package com.bx.implatform.controller;

import com.bx.implatform.result.Result;
import com.bx.implatform.result.ResultUtils;
import com.bx.implatform.service.IGroupService;
import com.bx.implatform.vo.GroupInviteVO;
import com.bx.implatform.vo.GroupMemberVO;
import com.bx.implatform.vo.GroupVO;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/group")
@RequiredArgsConstructor
public class GroupController {

    private final IGroupService groupService;

    @PostMapping("/create")
    public Result<GroupVO> createGroup(@RequestBody GroupVO vo) {
        return ResultUtils.success(groupService.createGroup(vo));
    }

    @PutMapping("/modify")
    public Result<GroupVO> modifyGroup(@RequestBody GroupVO vo) {
        return ResultUtils.success(groupService.modifyGroup(vo));
    }

    @DeleteMapping("/delete/{groupId}")
    public Result deleteGroup(@PathVariable Long groupId) {
        groupService.deleteGroup(groupId);
        return ResultUtils.success();
    }

    @GetMapping("/find/{groupId}")
    public Result<GroupVO> findGroup(@PathVariable Long groupId) {
        return ResultUtils.success(groupService.findById(groupId));
    }

    @GetMapping("/list")
    public Result<List<GroupVO>> findGroups() {
        return ResultUtils.success(groupService.findGroups());
    }

    @PostMapping("/invite")
    public Result invite(@RequestBody GroupInviteVO vo) {
        groupService.invite(vo);
        return ResultUtils.success();
    }

    @GetMapping("/members/{groupId}")
    public Result<List<GroupMemberVO>> findGroupMembers(@PathVariable Long groupId) {
        return ResultUtils.success(groupService.findGroupMembers(groupId));
    }

    @DeleteMapping("/quit/{groupId}")
    public Result quitGroup(@PathVariable Long groupId) {
        groupService.quitGroup(groupId);
        return ResultUtils.success();
    }

    @DeleteMapping("/kick/{groupId}")
    public Result kickGroup(@PathVariable Long groupId,
                            @RequestParam Long userId) {
        groupService.kickGroup(groupId, userId);
        return ResultUtils.success();
    }

}

